package com.xuzz.study.springbootdemo.filter;


import org.springframework.util.StopWatch;

import javax.servlet.*;
import java.io.IOException;

public class TimeFilter implements javax.servlet.Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("time filter init...");
    }

    @Override
    public void destroy() {
        System.out.println("time filter destroy...");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("time filter start ....");
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        filterChain.doFilter(servletRequest, servletResponse);
        stopWatch.stop();
        System.out.println(stopWatch.prettyPrint());
        System.out.println("time filter end ....");
    }
}
